package com.markerhub.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.markerhub.entity.Blog;
import com.markerhub.entity.Tag;
import com.markerhub.mapper.TagMapper;
import com.markerhub.service.TagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {
    @Autowired
    TagMapper tagMapper;
    //分页查询标签
    @Override
    public IPage<Tag> getTags(long current, long size, String column, int sort,String querycontent){
        QueryWrapper<Tag> queryWrapper = new QueryWrapper<>();
        if(querycontent!=null&&querycontent!="")
             queryWrapper.eq("tag_name",querycontent);
        //设置升序或者降序
        if( 0 == sort){
            //升序
            queryWrapper.orderByAsc(column);
        }else{
            //降序
            queryWrapper.orderByDesc(column);
        }
        IPage<Tag> tagIPage = tagMapper.selectPage(new Page<Tag>(current, size), queryWrapper);
        return tagIPage;
    }

    //添加标签
    @Override
    public void addtag(String tagname){
        Tag tag=new Tag();
        tag.setTagName(tagname);
        tagMapper.insert(tag);
    }

    //删除
    @Override
    public void deletetag(Integer tagid){
        QueryWrapper<Tag> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("tag_id",tagid);
        tagMapper.delete(queryWrapper);
    }

    //修改
    @Override
    public void edit_tag(Integer tagid,String tagname)
    {
        Tag tag=tagMapper.selectById(tagid);
        tag.setTagName(tagname);
        tagMapper.updateById(tag);
    }

}
